package org.example.cloud.payment.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/payment")
public class PaymentController {

    @Value("${server.port}")
    private Integer port;

    @GetMapping
    public String payment(){
        //测试feign调用超时
        /*try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/
        System.out.println("服务:"+port+"支付服务调用成功");
        return "服务:"+port+"支付服务调用成功";
    }

    //测试hytrix
    @HystrixCommand
    @GetMapping("/hytrix/ok")
    public String hytrixOk333333(){
        //int i=10/0;
        System.out.println(Thread.currentThread().getName()+"--hytrixOk");
        return "ok";
    }

    @GetMapping("/no/hytrix/ok")
    public String noHytrixOk(){
        System.out.println(Thread.currentThread().getName()+"--noHytrixOk");
        return "notok";
    }
}
